﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Dapper;

namespace _180FrameWork.DataBaseHelper
{
    public interface IJintDB
    {
        /// <summary>
        /// 查找单个记录
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        dynamic Find(string sql);
        /// <summary>
        /// 查找单个记录
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        dynamic Find(string sql, IDictionary<string, object> param);
        /// <summary>
        /// 查找单个记录
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        dynamic Find(string sql, IDictionary<string, object> param, IDbTransaction tran);
        /// <summary>
        /// 查找单个记录
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        dynamic Find(string sql, IDictionary<string, object> param, IDbTransaction tran,string format);
        /// <summary>
        /// 查找记录集合
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        IList<dynamic> Query(string sql);
        /// <summary>
        /// 查找记录集合
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        IList<dynamic> Query(string sql, IDictionary<string, object> param);
        /// <summary>
        /// 查找记录集合
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        IList<dynamic> Query(string sql, IDictionary<string, object> param, IDbTransaction tran);
        /// <summary>
        /// 查找记录集合
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        IList<dynamic> Query(string sql, IDictionary<string, object> param, IDbTransaction tran,string format);
        /// <summary>
        /// 查找分页记录
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        PageData<dynamic> Page(string sql);
        /// <summary>
        /// 查找分页记录
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        PageData<dynamic> Page(string sql, IDictionary<string, object> param);

        /// <summary>
        /// 查找表格记录
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        GridData<dynamic> Grid(string sql);
        /// <summary>
        /// 查找表格记录
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        GridData<dynamic> Grid(string sql, IDictionary<string, object> param);
        /*
       /// <summary>
       /// 查找标准数据结构
       /// </summary>
       /// <param name="sql"></param>
       /// <returns></returns>
       DataTable QueryDataTable(string sql);
       /// <summary>
       /// 查找标准数据结构
       /// </summary>
       /// <param name="sql"></param>
       /// <param name="param"></param>
       /// <returns></returns>
       DataTable QueryDataTable(string sql, IDictionary<string, object> param);
       */
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        int Exec(string sql);
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        int Exec(string sql, IDictionary<string, object> param);
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        int Exec(string sql, IDictionary<string, object> param, IDbTransaction tran);

        /// <summary>
        /// 存储过程
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="param"></param>
        IDictionary<string, object> Sp(string spName, IDictionary<string, object>[] param);

        /// <summary>
        /// 开启事务
        /// </summary>
        /// <returns></returns>
        IDbTransaction BeginTran();
        /// <summary>
        /// 打开数据连接
        /// </summary>
        void Open();
        /// <summary>
        /// 关闭数据连接
        /// </summary>
        void Close();

        /// <summary>
        /// 匹配sql
        /// </summary>
        /// <param name="SQL"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        IList<string> Match(string SQL, IDictionary<string, object> param);
        /// <summary>
        /// 变更数据库
        /// </summary>
        /// <param name="databaseName"></param>
        void ChangeDatabase(string databaseName);

        #region ORM扩展
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        dynamic Get(string tableName, IDictionary<string, object> param);
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        dynamic Get(string tableName, IDictionary<string, object> param, IDbTransaction tran);
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        dynamic Get(string tableName, IDictionary<string, object> param, IDbTransaction tran,string format);
        
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        int Insert(string tableName, IDictionary<string, object> data);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        int Insert(string tableName, IDictionary<string, object> data, IDbTransaction tran);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="data"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        int Update(string tableName, IDictionary<string, object> data);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="data"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        int Update(string tableName, IDictionary<string, object> data, IDbTransaction tran);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        int Delete(string tableName, IDictionary<string, object> param);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        int Delete(string tableName, IDictionary<string, object> param, IDbTransaction tran);

        #endregion
    }
}
